import numpy as np
from matplotlib import pyplot as plt
import torch

fig = plt.figure()
x = np.arange(-4, 4, 0.025)
plt.plot(x,x**2)
plt.title("y = x^2")

def f(x):
    return x**2
def h(x):
    return 2*x


η = 0.25
ε = 0.1
x = 4
iters = 0
sum_square_grad = 0
X = []
Y = []
while iters<8000:
    iters+=1
    X.append(x)
    Y.append(f(x))
    sum_square_grad += h(x)**2
    x = x - η/np.sqrt(sum_square_grad+ε)*h(x)
    print(iters,x)
plt.plot(X,Y,"ro")
plt.show()

params = {

}
torch.optim.Adagrad( params= params, lr=1e-2, lr_decay=0, weight_decay=0, initial_accumulator_value=0 )